<template>
  <layout title="">
    <custom-form
      ref="custom-form"
      class="custom-form"
      v-model="currentRow"
      :FormList="formColumns"
      :mode="customMode"
      v-bind="formItemLayout"
      layout="horizontal"
    >
    </custom-form>
  </layout>
</template>

<script lang="ts">
import { Mixins, Component, Watch, Vue, Prop } from 'vue-property-decorator'
import EventsMixin from '@/mixin/events'
import { TableMixin, AuthMixin } from '@/mixin'

import { TableLayout } from '@/layouts'
import CustomForm from '@/components/src/Form'
import { publishServices, IPublish } from '@/common/services/publish'
import { PayUnitTypeMap, publishStatusMap } from '@/common/enum'
import { userModule } from '@/store/modules/user'
import { IPlant } from '@/common/services/famer'
import { isEmpty } from 'lodash-es'

@Component({
  components: {
    Layout: TableLayout,
    CustomForm
  }
})
export default class AdminList extends Mixins(
  EventsMixin,
  TableMixin,
  AuthMixin
) {
  @Prop({
    type: Object
  })
  public plant!: IPlant

  get isLarge() {
    return userModule.isLarge
  }

  public commonParams = {
    s_a_id: ''
  }

  public currentFarmland = {
    pay_unit: '',
    pay_price: ''
  }

  // 产品列表搜索条件
  public tableSearch = {
  }

  // 自定义mode
  public customMode = 'add'

  // 产品列表表格信息
  public columns: ITable.IColumn[] = []

  public tableApi = {
    list: publishServices.previewMembers
  }


  public mounted() {
    this.handlerAddGrainColumn()
  }

  public handlerAddGrainColumn() {
    const grains = [
      '水稻',
      '玉米',
      '小麦',
      '红苕',
      '马铃薯',
      '大豆',
      '绿豆',
      '豌葫豆',
      '高粱',
      '荞麦',
      '肾豆',
      '红小豆'
    ]
    let defaultValues: Record<string, string> = {}
    const grainsColumns = grains.map((item, index) => {
      const key = 'plant' + (index + 1)
      defaultValues[key] = '0.00'
      return {
        title: item,
        dataIndex: key,
        key,
        form: {
          type: 'a-input',
          placeholder: `请输入${item}面积`,
          disabled: true,
          isShowList: false
        }
      }
    })
    this.columns = this.columns.concat(grainsColumns)
    this.tableEdit(Object.assign({}, (isEmpty(this.plant) ? defaultValues : this.plant)))
  }

  public async getData() {
    const res = await this.getTableList()
  }
}
</script>

<style scoped lang="less">
.title, .sub-title {
  text-align: center;
}

/deep/ .ant-card-body {
  padding: 0!important;
}
  
@media print {
  @page {
    size: landscape;   /* auto is the initial value */
    margin: 0;  /* this affects the margin in the printer settings */
  }
  #public-detail {
    width: 1123px;
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
  }
  
  .title {
    margin: 20px auto;
  }
  /deep/ .print-public {
    display: none;
  }
  /deep/ .ant-table-fixed-columns-in-body {
    display: none;
  }
  /deep/ .ant-table-fixed-right {
    display: none;
  }
  /deep/ .ant-table-body {
    overflow: hidden!important;
  }
  // /deep/ .ant-table-thead > tr > th {
  //   border-bottom: none;
  // }
  // /deep/ .ant-table {
  //   col:nth-child(1) {
  //     width: 90px!important;
  //   }
  //   col:nth-child(2) {
  //     width: 90px!important;
  //   }
  //   col:nth-child(3) {
  //     min-width: 202px!important;
  //     width: 202px!important;
  //   }
  //   col:nth-child(4) {
  //     width: 100px!important;
  //   }
  //   col:nth-child(5) {
  //     width: 80px!important;
  //   }
  //   col:nth-child(6), col:nth-child(7) {
  //     width: 150px!important;
  //   }
  // }
}
</style>
